
#ifndef _TTG_PIPELINE_WIN32_WIN32ATOMICVALUES_
#define _TTG_PIPELINE_WIN32_WIN32ATOMICVALUES_
#include "Common/Definitions.h"

#include "../AtomicValues.h"
#include <windows.h>

namespace ttg
{
	namespace threads
	{
		namespace win32
		{
			//Contains atomic value, which can be safly used in diffrent threads.
			class Win32AtomicInt :public ttg_internal::threads::AtomicInt
			{
				private:
					volatile LONG val;
				public:
					//Creates atomic int.
					inline Win32AtomicInt(int value = 0)
							{ this->set(value); }
					//Returns current value.
					virtual int get()
							{ return val; }
					//Sets value.
					virtual void set(int value)
							{ InterlockedExchange(&val, (LONG)value); }
					//Exchanges given value with current.
					virtual int exchange(int value)
							{ return (int)InterlockedExchange(&val, (LONG)value); }
					//Increments value by one.
					virtual int inc()
							{ return (int)InterlockedIncrement(&val); }
					//Dicrements value by one.
					virtual int dec()
							{ return (int)InterlockedDecrement(&val); }
					//Increments value by value.
					virtual int add(int value)
							{ return (int)InterlockedExchangeAdd(&val, (LONG)value) + value; }
			};
		}
	}
}

namespace ttg
{
	namespace threads
	{
		typedef ttg::threads::win32::Win32AtomicInt AtomicInt;
	}
}

#endif
